package cn.ac.cintcm.synonymous;

import java.util.ArrayList;
import java.util.List;

public class Term implements Comparable {
    public static final int ATTRIBUTE_SIZE = 3;

    public static final int ATTRIBUTE_NAME = 0;

    public static final int ATTRIBUTE_TYPE = 1;

    public static final int ATTRIBUTE_COUNT = 2;

    //public static final int ATTRIBUTE_SOURCE = 3;
    
    private String name;
    private short category;
    private List<String> sourceList;
    
    public Term() {
        sourceList = new ArrayList<String>();
    }
    
    public Term(String string, short type) {
        sourceList = new ArrayList<String>();
        this.name = string;
        this.category = type;
    }

    public String[] toArray() {
        String[] values = new String[ATTRIBUTE_SIZE];
        values[ATTRIBUTE_NAME] = name;
        values[ATTRIBUTE_TYPE] = category + "";
        values[ATTRIBUTE_COUNT] = sourceList.size() + "";
        //values[ATTRIBUTE_SOURCE] = Util.array2String(getSourceList());
        return values;
    }
    
    public void addSource(String sourceId) {
        sourceList.add(sourceId);
    }
    
    public String getSource() {
        return Util.array2String(sourceList.toArray(new String[0]), Config.getItemSeperator());
    }

    public short getCategory() {
        return category;
    }

    public void setCategory(short category) {
        this.category = category;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String[] getSourceList() {
        
        return sourceList.toArray(new String[0]);
    }

    public int compareTo(Object o) {
        int value = -1;
        if (o != null && o instanceof Term){
            Term t = (Term) o;
            value =  t.getSourceList().length - this.sourceList.size();
        }
        return value;
    }
}
